home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / sea of chaos / sea_install.msi / _15C39AAA7726369D39812BD40F01CF6A / _F32E1E6DF7554D91870A732B6D21417A < prev    next >
Text File  |  2005-03-02  |  2KB  |  70 lines

  1. //water vertex shader:
  2. //adjusts alpha based on angle between surface normal and eye
  3. //1 directional light also applied
  4. //also does environmental reflection off water (env map should be fixed relative to axises)
  5. //Luke Lenhart
  6. //(C)2004-2005 Digipen Institute of Technology
  7.  
  8.  
  9. //world,view,projection transform
  10. float4x4 matWorld;
  11. float4x4 matWorldViewProj;
  12.  
  13. //camera position in world space
  14. float4 cameraPos;
  15.  
  16. //directional light (assumed to be the sun)
  17. float4 lgtDirection;
  18.  
  19. //shader input
  20. struct VS_INPUT
  21. {
  22.     float4 Pos : POSITION;
  23.     float4 Normal : NORMAL;
  24.     float4 Clr: COLOR0;
  25. };
  26.  
  27. //shader output
  28. struct VS_OUTPUT
  29. {
  30.     float4 Pos : POSITION;
  31.     float4 Color : COLOR;
  32.     float2 Tex0 : TEXCOORD0;
  33.     float3 Tex1 : TEXCOORD1;
  34.     //float FogClr : TEXCOORD2;
  35. };
  36.  
  37. //shader code
  38. VS_OUTPUT VShader(VS_INPUT In)
  39. {
  40.     VS_OUTPUT Out;
  41.     
  42.     //tex coord generated from position
  43.     Out.Tex0=In.Pos;
  44.     
  45.     //out position
  46.     Out.Pos=mul(matWorldViewProj,In.Pos);
  47.     
  48.     //calc directional light color
  49.     Out.Color=dot(In.Normal,lgtDirection)*In.Clr;
  50.     
  51.     //calc alpha based dot between vertex normal and vector from vertex to camera
  52.     //taken to a high power to spread translucent range over more of the angle range
  53.     //done in world space
  54.     float3 vecEyeToVertex=normalize(cameraPos-In.Pos);
  55.     float alpha=pow(1.0f-dot(vecEyeToVertex,In.Normal), 15.0f);
  56.     Out.Color+=alpha*float4(0.2f,0.2f,0.2f,0.0f);
  57.     Out.Color.a=(0.6f+alpha)*In.Clr.a;
  58.     
  59.     //calc env reflection vector
  60.     //done in world space
  61.     float3 tranNorm=In.Normal.xyz;
  62.     Out.Tex1=reflect(-vecEyeToVertex,tranNorm);
  63.     
  64.     //calc fog color
  65.     //Out.FogClr=saturate(log(distance(cameraPos.xyz,In.Pos.xyz))*0.08f - 0.1f);
  66.     
  67.     //spit out the results
  68.     return Out;
  69. }
  70.